<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>事件绑定并传参</title>
    <script src="./lib/vue-2.6.12.js"></script>
</head>
<body>
    <!-- Vue实例要控制的Dom区域 -->
    <div id="app">
        <h3>count的值为:{{count}}</h3>
        <button @click="addCount(2,$event)">+2</button>
    </div>

    <script>
        // 创建VM实例对象
        const vm=new Vue({
            // 指定当前vm要控制的区域
            el:'#app',
            data:{
                // 计数器的值
                count:0,
            },
            methods: {
                addCount(step,e){
                    const bgColor=e.target.style.backgroundColor;
                    e.target.style.backgroundColor=bgColor==='red'?'':'red';
                    this.count+=step;
                }
            },
        })
    </script>

</body>
</html>